package com.roy.ribbon;

import java.util.ArrayList;
import java.util.List;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

/**
 * ribbon负载均衡
 * @author roykingw
 */
public class BasicRibbonMain {
	public static void main(String[] args) {
		BaseLoadBalancer lb = new BaseLoadBalancer();
		//添加服务列表
		List<Server> servers = new ArrayList<Server>();
		servers.add(new Server("localhost",8080));
		servers.add(new Server("localhost",8081));
		servers.add(new Server("localhost",8082));
		servers.add(new Server("localhost",8083));
		lb.addServers(servers);
		//自定义规则
		MyRule myrule = new MyRule();
		myrule.setLoadBalancer(lb);
		lb.setRule(myrule);
		for(int i = 0 ; i < 10 ; i ++) {
			Server server = lb.chooseServer(null);
			System.out.println(server);
		}
	}
}
